<?php

namespace IDock\Insurance\DAJIA\Request;

use IDock\Insurance\DAJIA\Request\AllDAJIARequest;
use IDock\Insurance\DAJIA\Response\CommonResponse;
use IDock\Insurance\DAJIA\Response\InsuranceOrderQueryResponse;
use IDock\Insurance\DAJIA\Response\UploadFileResponse;
use IDock\Visitor\UploadFileVisitor;

/**
 * 影像上传接口
 */
class UploadFileRequest extends AllDAJIARequest
{
    protected $code = 'ODR1013';

    protected $response = UploadFileResponse::class;

    protected $urlTip = '影像上传接口';

    /**
     * @var UploadFileVisitor $visitor
     */
    protected $visitor;

    protected $inLog = false;

    public function generate(): array
    {
        return [
            'orderNo' => $this->visitor->argc['orderNo'],
            'syProposalNo' => $this->visitor->biInquiryNo,
            'jqProposalNo' => $this->visitor->ciInquiryNo,
            'appCode' => '80',
            'dataId' => '8001',
            'appType' => ($this->visitor->argc['busiDataSrc'] ?? '').'_'.($this->visitor->argc['busiDataFlag'] ?? ''),
            'orgNum' => $this->visitor->argc['busiDptCde'] ?? '',
            'oprId' => $this->visitor->argc['busiOprCde'] ?? '',
            'upType' => '1',//上传方式 1（文件流），2（ftp）
            'imageList' => $this->getImageList()
        ];
    }

    private function getImageList()
    {
        $imgList = [];
        foreach ($this->visitor->getFileList() as $val){
            $baseName = basename($val['url']);
            $ext = explode('.',$baseName);
            $imgList[] = [
                'imgName' => $baseName,//要求英文
                'base64Img' => base64_encode(file_get_contents($val['url'])),//图片base64编码
                'filedSuffix' => $ext[1] ?? '',//文件后缀
//                'filedPath' => $val['url'],//图片地址 ftp模式必传
            ];
        }
        return $imgList;
    }


}
